package com.bawan.vims.xsocket;

import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.channels.ClosedChannelException;

import org.xsocket.MaxReadSizeExceededException;
import org.xsocket.connection.IConnectHandler;
import org.xsocket.connection.IDataHandler;
import org.xsocket.connection.IDisconnectHandler;
import org.xsocket.connection.IIdleTimeoutHandler;
import org.xsocket.connection.INonBlockingConnection;

public class XSocketHandler implements IDataHandler, IConnectHandler, IDisconnectHandler,IIdleTimeoutHandler  {

	@Override
	public boolean onConnect(INonBlockingConnection connection)
			throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
		System.out.println(connection.getId() + " is connect");
		return true;
	}
	
	@Override
	public boolean onDisconnect(INonBlockingConnection connection)
			throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
		System.out.println(connection.getId() + " is disconnect");
		return true;
	}
	
	@Override
	public boolean onData(INonBlockingConnection connection)
			throws IOException, BufferUnderflowException, ClosedChannelException, MaxReadSizeExceededException {
		String str = connection.readStringByDelimiter("\0");
		System.out.println(str);
		return true;
	}

	@Override
	public boolean onIdleTimeout(INonBlockingConnection connection) throws IOException {
		return false;
	}
	
}
